package org.example.usercontroller;

import lombok.extern.slf4j.Slf4j;
import org.example.pojo.userdto.CartBeanDTO;
import org.example.pojo.Result;
import org.example.userservice.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;
    @PostMapping("/add")
    public Result add(@RequestBody CartBeanDTO cartBeanDTO) {
        log.info("add cartBean: {}", cartBeanDTO);
        if(shoppingCartService.addShoppingCart(cartBeanDTO)) {
            return Result.success();
        }else{
            return Result.error("库存不足！");
        }


    }
    @GetMapping("/list")
    public Result list() {
        log.info("list");
        return Result.success(shoppingCartService.ShoppingCartlist());
    }
    @DeleteMapping("/clean")
    public Result clean(){
        log.info("clean");
        shoppingCartService.deleteShoppingCart();
        return Result.success();
    }
}
